package com.xust.oa.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xust.oa.domain.dto.PositionDTO;
import com.xust.oa.domain.entity.TPosition;
import com.xust.oa.mapper.TPositionMapper;
import com.xust.oa.service.TPositionService;
import com.xust.oa.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


import java.util.List;

/**
* @author ZHANGJIE
* @description 针对表【t_position】的数据库操作Service实现
* @createDate 2025-03-25 22:24:35
*/
@Service
public class TPositionServiceImpl extends ServiceImpl<TPositionMapper, TPosition>
implements TPositionService{


    @Autowired
    private TPositionMapper PositionMapper;

    @Override
    public Result<List<TPosition>> searchList(PositionDTO positionDTO) {
        Integer pageNum = positionDTO.getPageNum();
        if (pageNum == null || pageNum < 1) pageNum = 1;
        Integer pageSize = positionDTO.getPageSize();
        if (pageSize == null || pageSize < 1) pageSize = 10;
        Page<TPosition> page = new Page<>(pageNum, pageSize);

        QueryWrapper<TPosition> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(positionDTO.getName()))
            queryWrapper.like("name", positionDTO.getName());
        if (!StringUtils.isEmpty(positionDTO.getEnabled()))
            queryWrapper.eq("enabled", positionDTO.getEnabled());

        // 执行分页查询
        IPage<TPosition> pageResult = PositionMapper.selectPage(page, queryWrapper);
        // 获取分页结果中的数据列表
        List<TPosition> list = pageResult.getRecords();
        return Result.ok(list,"查询成功");
    }

}
